package cn.com.kh;

import cn.com.elite.Util;
import net.sf.json.JSONArray;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DevTest {
    private static final Log log = LogFactory.getLog(DevTest.class);
    private static final String SIGN_KEY = "sign";

    private static Map<String, String> map = new ConcurrentHashMap<String, String>();

    public static void main(String[] args) throws Exception {

        String Rawfile = "[{\"url\":\"http://xxxxx1,http://xxxxx2\"},{\"url\":\"http://xxxxx3\"},{\"url\":\"http://xxxxx4,http://xxxxx5\"}]";
        try {
            if (Rawfile.indexOf(",http:") >= 0) {
                JSONArray fileArr = JSONArray.fromObject(Rawfile);
                List<Map<String, String>> fileList = new ArrayList<>();
                for (int j = 0; j < fileArr.size(); j++) {
                    log.debug("当前处理数组对象-" + fileArr.getJSONObject(j));
                    String[] tempURL = fileArr.getJSONObject(j).getString("url").split(",");
                    log.debug("当前处理文件地址分割后长度-" + tempURL.length);
                    for (int k = 0; k < tempURL.length; k++) {
                        Map<String, String> tempU = new HashMap<>();
                        tempU.put("url", tempURL[k]);
                        fileList.add(tempU);
                    }
                }
                Rawfile = Util.getJsonArrayFromList(fileList).toString();
                log.debug("综调系统调用的文件数据格式需要预处理...处理后结果:" + Rawfile);
            } else {
                log.debug("综调系统调用的文件数据格式不需要预处理...");
            }

        } catch (Exception e) {
            log.error("附件类表数据保护:", e);
        }
        System.out.println(Rawfile);


    }

}
